;
(function(doc) {
    var oCalculator = doc.getElementsByClassName('calculator')[0];
    var oResult = oCalculator.getElementsByClassName('result')[0];
    var fInput = oCalculator.getElementsByTagName('input')[0];
    var sInput = oCalculator.getElementsByTagName('input')[1];
    var btnGroup = oCalculator.getElementsByClassName('btn-group')[0]

    //获取dom

    var init = function() {
        bindEvent();
    }

    //初始执行函数

    function bindEvent() {
        btnGroup.addEventListener('click', btnClick, false)
    }

    //点击触发函数

    function btnClick(eve) {
        var e = eve || window.event;
        var tar = e.target || e.srcElement;
        var tagName = tar.tagName.toLowerCase();

        if (tagName === 'button') {
            var method = tar.getAttribute('data-method');
            var fVal = Number(fInput.value.replace(/\s+/g, '')) || 0;
            var sVal = Number(sInput.value.replace(/\s+/g, '')) || 0;

            genderResult(compute(method, fVal, sVal))
        }
    }

    // 点击事件函数

    function genderResult(result) {
        oResult.innerText = result
    }

    //返回结果函数

    function compute(method, fVal, sVal) {
        switch (method) {
            case 'plus':
                return fVal + sVal
                break;
            case 'minus':
                return fVal - sVal
                break;
            case 'mul':
                return fVal * sVal
                break;
            case 'div':
                return fVal / sVal
                break;
            default:
                break;
        }
    }

    //计算函数

    init()

})(document)